//Cracking the coding interview (5th), 1_8
// Assume you have a method isSubstring which checks if one word is a substring of another. Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 using only one call to is Substring (e.g., "waterbottle" is a rotation of "erbottlewat").
//950PM -- 956PM -- 957PM (bug free)

#include<iostream>
#include<string>
using namespace std;

bool isSubstring(string &str1, string &str2)
{
  return str2.find(str1) != string::npos; 
}

bool isRotate(string &str1, string &str2)
{
  string str3 = str1 + str1;
  return isSubstring(str2, str3);
}

int main(int argc, char *argv[])
{
  string str1("waterbottle");
  string str2("erbottlewat");
  string str3("waterottleb");

  bool b1 = isRotate(str1, str2);
  bool b2 = isRotate(str1, str3);
  
  cout<<b1<<endl<<b2<<endl;
  return 0;
}
